﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Torch_Services
{
    public class BannerPhotoBll : IBannerPhotoBll
    {
        private IBannerPhotoDal _banner;
        private IMapper _mapper;
        public BannerPhotoBll(IBannerPhotoDal banner, IMapper mapper)
        {
            _banner = banner;
            _mapper = mapper;
        }

        public Task<int> AddBannerPhotoAsync(string photoPath)
        {
            return _banner.AddAsync(new Bannerphoto 
            {
                PhotoPath = photoPath
            });
        }

        public async Task<int> DeleteBannerPhotoAsync(int id)
        {
            var data = await _banner.QueryAsync(id);
            return data == null ? -1 : await _banner.DeleteAsync(data);
        }

        public async Task<int> EditBannerPhotoAsync(int id, string photoPath)
        {
            var data = await _banner.QueryAsync(id);
            if (data == null)
                return -1;
            data.PhotoPath = photoPath;
            return await _banner.EditAsync(data);
        }

        public async Task<List<BannerPhotoDto>> GetBannerPhotoAllAsync()
        {
            var data = await _banner.QueryAsync();
            return _mapper.Map<List<Bannerphoto>,List<BannerPhotoDto>>(data);
        }

        public async Task<BannerPhotoDto> QueryBannerPhotoByIdAsync(int id)
        {
            var data = await _banner.QueryAsync(id);
            return _mapper.Map<Bannerphoto,BannerPhotoDto>(data);
        }
    }
}
